package com.nisco.dms.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.nisco.dms.entity.SqlTable;
import com.nisco.dms.repository.SqlTableDao;
import com.nisco.dms.util.dwz.Page;
import com.nisco.dms.util.dwz.PageUtils;

/**
 * 
 * @author Robin
 * 
 */
@Component
@Transactional(readOnly = true)
public class SqlTableService extends BaseService<SqlTable, String> {

	private SqlTableDao sqlTableDao;

	public SqlTableService() {

	}

	@Autowired
	public SqlTableService(SqlTableDao sqlTableDao) {
		super(sqlTableDao);
		this.sqlTableDao = sqlTableDao;
	}

	@Autowired
	public void setSqlTableDao(SqlTableDao sqlTableDao) {
		this.sqlTableDao = sqlTableDao;
	}

	/**
	 * 查询分页
	 * 
	 * @param compId
	 * @param page
	 * @return
	 */
	public List<SqlTable> find(String tabName, Page page) {
		org.springframework.data.domain.Page<SqlTable> p = sqlTableDao
				.findByTabNameContaining(tabName,
						PageUtils.createPageable(page));
		PageUtils.injectPageProperties(page, p);
		return p.getContent();
	}

	/**
	 * 查找无字段的表名
	 * @return
	 */
	public SqlTable findByStatus(){
		return sqlTableDao.findByStatus("N");
	}
	
	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	public SqlTable findOne(String id) {
		return sqlTableDao.findOne(id);
	}
}
